package syn;

import java.util.ArrayList;
import java.util.List;

/**
 * Remarks:
 * ArrayList是线程不安全的
 * Class name :UserfeList
 * Date :2023/2/15 13:09
 * Author:杨俊源
 */
public class UnsafeList {

    public static void main(String[] args) {
        List<String> list = new ArrayList<>();

        for (int i = 0; i < 10000; i++) {
            new Thread(() -> {
                synchronized (list) {
                    list.add(Thread.currentThread().getName());
                }
            }).start();
            ;
        }
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("list.size() = " + list.size());
    }
}
